Skip to content

own: a let given only fields borrows each until the next assignment; a let that only holds parameters owns nothing (TSLANG 56, 57) - #850

Merged
ASDAlexander77 merged 2 commits into
mainfrom
fix-own-items-56
Nov 14, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
fix-own-items-56

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

TSLANG_ISSUES 56 and 57, found by compiling powder_sandbox's -mm=own build (native_ts_graphics as its submodule) with the compiler from main. Write-ups are in TSLANG_ISSUES.md.

56: a let given only fields borrows each until the next assignment

let layout = this.computeLayout; ... if (this.fp16Enabled) { layout = this.computeLayoutFP16; ... } (ntg examples/nri/16bit_arithmetic_nri.ts) was refused: "borrows a field and cannot be assigned; -mm=own cannot prove that yet".

  • Which locals: an owning let qualifies (borrowsOnly) when its declaration and every assignment give it a read of a place or a parameter.
  • How the borrows are bounded: each value's borrow covers only the reads its own store reaches before another assignment, and the assignments end it (collectBorrowerUses, with the store as from).
  • The assignment itself: its Store, and rc's Retain right before it, are taken as that read's borrower and bookkeeping (borrowingAssignmentOf, in checkPlaceRead).
  • Now accepted: a field written once the let holds another field, in a loop too.
  • Still refused:
    • the field the let currently holds written before a use, directly or through a call;
    • the let stored or returned;
    • a fresh value assigned to it (the camera's dir = rotateAround(...)).
  • One sound case is still refused: in a loop that reads the let, reassigns it, then writes the first field, a read after the loop is taken to see the first field.

57: a let that only holds parameters owns nothing

let src = order; let dst = scratch; ... const swap = src; src = dst; dst = swap; (ntg core/octomap_common.ts, the exported sortDescending) was refused: "a parameter, kept here, but -mm=own cannot make the callers ... give it up". So was let s = a; return s.length;.

  • The cause: MLIRGen makes every let an owning local, so storing a parameter into one counted as keeping the parameter.
  • The fix: borrowParametersInLocals runs at the start of the signature pass, before the facts. It turns a let that only ever holds parameters, or another such let's value, into a plain local and drops rc's counting for it.
  • Left as they were: Shared<T> handles, which own counts, and copyable values such as strings.
  • Still refused: storing such a let, capturing it, or giving it a fresh value. These are refused as they would be for the parameter itself.
  • Result: octomap_common.ts compiles under own, and with it examples/render_octomap.ts.

Effect on the sweep (276 sources, every facts object built)

  • Sources failing: 143 → 141.
  • Errors from borrow-only lets: all gone. What remains in donut_first_person_camera.ts is the camera's two, where a fresh array is assigned.
  • ntg core/ modules that don't compile under own: 7 → 6.
  • No file got worse, and powder_sandbox's own src/ compiles clean.

Also noted in TSLANG_ISSUES.md, for native_ts_graphics rather than the compiler: ray_tracing_extended_scene.ts's exported constructors need @keeps(...). I checked that @keeps works on a constructor.

Tests

  • New tests: 00tslang_issue_56.ts and 00tslang_issue_57.ts, under every model, JIT and compiled. Both were also run as an exe by hand.
  • New own error tests: own_err_let_borrows_reassigned_overwritten and own_err_parameter_let_stored.
  • ctest (Windows Release): 7238/7238.
  • DefaultLib main rebuilt with this compiler, release and debug, all four models. tests.ps1 for each model is running; results to follow in a comment.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 14, 2026 14:05
…TSLANG 56)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77

Copy link
Copy Markdown
Owner Author

DefaultLib tests.ps1 with this branch's compiler (DefaultLib main rebuilt, release and debug, all four models). No failures; the skips are the usual by-design ones.

model release compile release jit debug compile debug jit
own 216/221, 5 skipped 216/221, 5 skipped 216/221, 5 skipped 216/221, 5 skipped
rc 217/221, 4 skipped 217/221, 4 skipped 217/221, 4 skipped 217/221, 4 skipped
gc 220/221, 1 skipped 220/221, 1 skipped 220/221, 1 skipped 220/221, 1 skipped
none 217/221, 4 skipped 217/221, 4 skipped 217/221, 4 skipped 217/221, 4 skipped

@ASDAlexander77
ASDAlexander77 merged commit adc84d5 into main Nov 14, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-own-items-56 branch November 14, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant